package com.llp.declaresystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.llp.declaresystem.dao.AdminProjectDao;
import com.llp.declaresystem.domain.entity.Expert;
import com.llp.declaresystem.domain.entity.Unit;
import com.llp.declaresystem.service.*;
import kotlin.UInt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author llp
 * {@code @date} 2022年11月27日17:14
 * admin的项目Dao
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminProjectDao adminProjectDao;
    @Autowired
    UserService userService;
    @Autowired
    ExpertService expertService;
    @Autowired
    UnitService unitService;
    @Autowired
    UseradminService useradminService;
    @Autowired
    UsergroupService usergroupService;


    @Override
    public boolean deleteProjectByCategoryid(Integer categoryid) {
        boolean b=adminProjectDao.deleteProject(categoryid);
        return  b;
    }

    @Override
    public boolean deleteUser(Integer uid, Integer gid) {
        //根据gid先删除admin,或者expert,或者unit
        if(gid==1)
        {
         useradminService.removeById(gid);
        }
        else if(gid==2)
        {
            QueryWrapper<Expert> wrapper = new QueryWrapper<>();
            wrapper.eq("uid",uid);
            expertService.remove(wrapper);
        }
        else if(gid==3)
        {
            QueryWrapper<Unit> wrapper = new QueryWrapper<>();
            wrapper.eq("uid",uid);
            unitService.remove(wrapper);

        }
        boolean result = userService.removeById(uid);
        if (result) return true;
        return false;
    }
}
